<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
    <% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
        + request.getServerPort() + path + "/" ; %>

        <!DOCTYPE html>
        <html>

        <head>
            <base href="<%=basePath%>">

            <title></title>

            <meta http-equiv="pragma" content="no-cache">
            <meta http-equiv="cache-control" content="no-cache">
            <meta http-equiv="expires" content="0">
            <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
            <meta http-equiv="description" content="This is my page">
            <!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

        </head>

        <body>
            <%@ include file="/WEB-INF/jsp/common/header.jsp" %>
                <%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

                    <script type="text/javascript">
                        $(function () {
                            $('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
                            $('#endTime').datebox('setValue', getNowFormatDate());
                            bindgrid();
                        });
                    </script>

                    <script type="text/javascript">
                        var selectedFileList = [];//已选文件列表
                        var succsessCount = 0;//上传成功文件个数
                        var errorCount = 0;//上传失败文件个数
                        /************文件处理部分*************/


                        /**
                         *文件框改变事件
                         */
                        function changeFile() {
                            var files = $("#uploadpicker").prop("files");
                            $
                                .each(
                                    files,
                                    function (index, item) {
                                        let choiseFile = $("#checkfileList>li");
                                        if (choiseFile.length > 0) {//文件去重
                                            let count = 0;
                                            $.each(choiseFile, function (index1, item1) {
                                                if (item.name == item1.innerText) {
                                                    count++;
                                                }
                                            });
                                            if (count == 0) {
                                                if (checkFileLength(item.size)) {
                                                    if (item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                        alert('文件名不能包含&、\\、空格等特殊字符！');
                                                        return;
                                                    }
                                                    $("#checkfileList")
                                                        .append(
                                                            "<li class=\"fileinfo\">"
                                                            + item.name
                                                            + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                            + item.name
                                                            + "')\">删除</a>"
                                                            + "</li>");
                                                    selectedFileList.push(item);
                                                    AddMoushover();
                                                }
                                            }
                                        } else {
                                            if (checkFileLength(item.size)) {
                                                if (item.name.includes('&') || item.name.includes('\\') || item.name.includes(' ')) {
                                                    alert('文件名不能包含&、\\、空格等特殊字符！');
                                                    return;
                                                }
                                                $("#checkfileList")
                                                    .append(
                                                        "<li class=\"fileinfo\">"
                                                        + item.name
                                                        + "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                                        + item.name
                                                        + "')\">删除</a>"
                                                        + "</li>");
                                                selectedFileList.push(item);
                                                AddMoushover();
                                            }
                                        }
                                    });
                        }

                        /**
                         *    判断文件是否超过限制大小
                         * @param fileLen
                         * @returns {boolean}
                         */
                        function checkFileLength(fileLen) {
                            if (fileLen > 102400000) {
                                $.messager.alert("提示", "上传文件大小不能超过100M", "error");
                                return false;
                            }
                            return true;
                        }

                        /**
                         * //添加鼠标经过事件，鼠标划过时显示“删除”
                         * @constructor
                         */
                        function AddMoushover() {
                            $(".fileinfo").hover(function () {
                                $(this).find("a").last().css("display", "");
                            }, function () {
                                $(this).find("a").last().css("display", "none");
                            });
                        }

                        /**
                         *  移除已选择的文件
                         */

                        function RemoveFile(obj, fileId) {
                            $.messager.confirm("提示", "确认删除当前文件?", function (e) {
                                if (e) {
                                    let index = $("#checkfileList>li").index($(obj).parent());
                                    selectedFileList.splice(index, 1);
                                    $(obj).parent().remove();

                                    $.ajax({
                                        type: "post",
                                        url: 'file/deleteFile?fileId=' + fileId,
                                        success: function (data) {
                                            $.messager.alert('消息', data);
                                        },
                                        error: function (XMLHttpRequest, textStatus,
                                            errorThrown) {
                                            $.messager.alert('消息', errorThrown);
                                        }
                                    });

                                }
                            });
                        }

                        /**
                         * 取得该条数据所属的文件列表
                         * @param row
                         */
                        function getFileList(id) {
                            $.ajax({
                                type: "post",
                                url: "file/getFileList",
                                data: {
                                    fileTable: "con_visa",
                                    fileRow: id
                                },
                                success: function (data) {
                                    const dataArray = eval(data);
                                    initFile(dataArray);
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        /**
                         * 初始化该条数据的文件列表
                         * @param dataArray
                         */
                        function initFile(dataArray) {
                            $("#checkfileList").empty();
                            // 			sselectedFileNameList = [];
                            selectedFileList = [];
                            dataArray
                                .forEach(function (e, i, a) {
                                    $("#checkfileList")
                                        .append(
                                            "<li class=\"fileinfo\">"
                                            + "<a style=\" color: blue; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"downloadFile('"
                                            + e.FILE_NAME
                                            + "','"
                                            + e.FILE_ID
                                            + "')\">"
                                            + e.FILE_NAME
                                            + "</a>"
                                            + "<a style=\"display: none; color: red; margin-left: 30px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this,'"
                                            + e.FILE_ID + "')\">删除</a>"
                                            + "</li>");
                                    // 						sselectedFileNameList.push(e.FILE_NAME);
                                    AddMoushover();
                                });
                        }

                        // 文件下载
                        function downloadFile(fileName, fileRow) {
                            let url = 'api/file/download?id=' + fileRow
                            let xhr = new XMLHttpRequest()
                            xhr.open('GET', url, true)
                            xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function (data) {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = fileName
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                } else {

                                }
                            }
                            xhr.send()
                        }
                    </script>
                    <script>
                        function del(node) {
                            $.ajax({
                                type: "delete",
                                //url: 'qm/lims/broadcasts/delete?'  +'spId=' + node.spId ,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    selectList();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function back(node) {
                            $.ajax({
                                type: "get",
                                url: 'qm/lims/broadcasts/back?' + 'spId=' + node.spId,
                                //                dataType: "xml",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    $('#add').window('close');
                                    selectList();
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            });
                        }

                        function save(status) {
                            if (!$('#fm').form('validate')) {
                                return;
                            }
                            var row = $('#dg').datagrid('getSelected');
                            var model = {
                                spId: $('#spId ').textbox('getValue'),
                                samNo: $('#samNo ').textbox('getValue'),
                                samName: $('#samName ').textbox('getValue'),
                                samStatus: $('#samStatus ').textbox('getValue'),
                                recDate: $('#recDate ').textbox('getValue'),
                                subDate: $('#subDate ').textbox('getValue'),
                                pusDate: $('#pusDate ').textbox('getValue'),
                                subBroadcast: $('#subBroadcast ').textbox('getValue'),
                                recBroadcastNum: $('#recBroadcastNum ').textbox('getValue'),
                                createTime: $('#createTime ').textbox('getValue'),
                                createId: $('#createId ').textbox('getValue'),
                                createName: $('#createName ').textbox('getValue'),
                                updateId: $('#updateId ').textbox('getValue'),
                                updateTime: $('#updateTime ').textbox('getValue'),
                                updateName: $('#updateName ').textbox('getValue')
                            };
                            model.status = '0';
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'qm/lims/broadcasts/save',
                                data: JSON.stringify(model),
                                contentType: "application/json",
                                success: function (data) {
                                    $.messager.alert('消息', data.msg);
                                    if (data.code != 60200) {
                                    } else {
                                        saveAttch(data.data, status)
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })

                        }

                        function commit(obj) {
                            obj.status = '1'
                            $.ajax({
                                type: "post",
                                dataType: "json",
                                url: 'qm/lims/broadcasts/commit',
                                data: JSON.stringify(obj),
                                contentType: "application/json",
                                success: function (data) {
                                    if (data.code != 60200) {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                    } else {
                                        $.messager.alert('消息', data.msg);
                                        selectList();
                                        $('#add').window('close');
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $.messager.alert('消息', errorThrown);
                                }
                            })
                        }

                        /**
                         * 保存附件
                         */
                        function saveAttch(row, rowId, action) {
                            let saveNum = 0
                            if (selectedFileList.length > 0) {
                                $.each(selectedFileList, function (index, item) {
                                    showFilediv();
                                    var dataform = new FormData();
                                    dataform.append("file", item);
                                    var xmlhttp = null;
                                    if (window.XMLHttpRequest) {// code for all new browsers
                                        xmlhttp = new XMLHttpRequest();
                                    } else if (window.ActiveXObject) {// code for IE5 and IE6
                                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                                    }
                                    if (xmlhttp != null) {
                                        xmlhttp.open("POST", "api/file/springUpload?fileRow=" + rowId
                                            + "&fileTable=con_visa&fileName="
                                            + item.name, true);
                                        xmlhttp.setRequestHeader('token', localStorage.getItem('token'));
                                        xmlhttp.setRequestHeader('userType', localStorage.getItem('userType'));
                                        xmlhttp.send(dataform);
                                        xmlhttp.onreadystatechange = callbackMethods;
                                    } else {
                                        alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
                                    }

                                    function callbackMethods() {
                                        if (xmlhttp.readyState == 4) {
                                            if (xmlhttp.status == 200) {
                                                saveNum += 1
                                                if (saveNum == selectedFileList.length) {
                                                    hideFilediv();
                                                    if ('1' == action) {
                                                        commit(row)
                                                    } else {
                                                        $.messager.alert('消息', '保存成功！');
                                                        selectList();
                                                        $('#add').window('close');
                                                    }
                                                }
                                            }
                                        } else {
                                            if (xmlhttp.status == 500) {
                                            }
                                        }
                                    }
                                });
                            } else {
                                if ('1' == action) {
                                    commit(row)
                                } else {
                                    $.messager.alert('消息', '保存成功！');
                                    selectList();
                                    $('#add').window('close');
                                }
                            }
                        }

                        function editrow(row) {
                            //编辑用户
                            var row = $('#dg').datagrid('getSelected');
                            if (row) {
                                $('#add').window('open');
                                $('#fm').form('load', row);
                                initBtn(row.status);

                            } else {
                                $.messager.alert('消息', '请选中一条数据');
                            }
                        }
                    </script>
                    <script>

                        function initBtn(status) {
                            if (status == '0') {
                                $('#tabs').tabs({
                                    tools: [{
                                        text: '保存',
                                        iconCls: 'icon-save',
                                        handler: function () {
                                            save('0');
                                        }
                                    }, {
                                        text: '提交',
                                        iconCls: 'icon-ok',
                                        handler: function () {
                                            $.messager.confirm('提示', '提交后无法再次编辑，确定要提交吗?',
                                                function (r) {
                                                    if (r) {
                                                        save('1');
                                                    }
                                                });
                                        }
                                    }]
                                })
                            } else {
                                $('#tabs').tabs({
                                    tools: null
                                })
                            }
                        }

                        /**
                         *  按条件查询报价列表
                         */
                        function selectList() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')
                            //  var status = $('#status').combobox('getValue');
                            var dg = $('#dg');
                            dg.datagrid('enableFilter');
                            dg.datagrid('load', {
                                startTime: startTime ? startTime : '',
                                endTime: endTime ? endTime : ''
                            });
                        }

                        function bindgrid() {
                            var startTime = $('#startTime').datebox('getValue')
                            var endTime = $('#endTime').datebox('getValue')

                            $('#dg').datagrid({
                                title: '样品列表',
                                queryParams: {
                                    startTime: startTime,
                                    endTime: endTime

                                },
                                url: "lims/broadcasts/selectList",
                                iconCls: 'icon-application',
                                width: getWidth(0.98),
                                height: 415,
                                nowrap: true,
                                filterDelay: 0,
                                rownumbers: true,
                                animate: false,
                                collapsible: false,
                                clientPaging: false,
                                remoteFilter: true,
                                singleSelect: true,
                                pagination: true,
                                remoteSort: true,
                                frozenColumns: [[]],
                                columns: [[{
                                    field: 'spId',
                                    title: '播报id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'samNo',
                                    title: '样品编号',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'samName',
                                    title: '样品名称',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'samStatus',
                                    title: '样品状态',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        let name = '--'
                                        if (val == '0') {
                                            name = '未提交'
                                        }
                                        if (val == '1') {
                                            name = '已提交'
                                        }
                                        if (val == '2') {
                                            name = '未打印'
                                        }
                                        return name
                                    }
                                }, {
                                    field: 'recDate',
                                    title: '接收时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'subDate',
                                    title: '提交时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'pusDate',
                                    title: '发布时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'pusNoPrintNum',
                                    title: '未打印COA播报次数',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '0';
                                    }
                                }, {
                                    field: 'subBroadcast',
                                    title: '已提交播报次数',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '0';
                                    }
                                }, {
                                    field: 'recBroadcastNum',
                                    title: '未提交播报次数',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '0';
                                    }
                                }, {
                                    field: 'updateTime',
                                    title: '播报时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createTime',
                                    title: '创建时间',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createId',
                                    title: '创建人',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'createName',
                                    title: '创建人姓名',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateId',
                                    title: '更新人id',
                                    sortable: true,
                                    hidden: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }, {
                                    field: 'updateName',
                                    title: '更新人姓名',
                                    sortable: true,
                                    formatter: function (val, rec) {
                                        return val ? unescape(val) : '';
                                    }
                                }]],
                                onLoadSuccess: function () {
                                },
                                onDblClickRow: function () {
                                    /* var row = $('#dg').datagrid('getSelected');
                                     editrow(row);*/
                                }
                            });
                            $('#dg').datagrid('enableFilter');
                        }


                        // 导出为Excel
                        function exportList() {
                            let startTime = $('#startTime').datebox('getValue')
                            let endTime = $('#endTime').datebox('getValue')
                            var form = [];
                            form.push('startTime=' + (startTime ? startTime : ''));
                            form.push('endTime=' + (endTime ? endTime : ''));
                            let url = "qm / lims / broadcasts/export"
                            let xhr = new XMLHttpRequest()
                            xhr.open('POST', url, true)
                            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                            xhr.setRequestHeader('token', localStorage.getItem('token'));
                            xhr.setRequestHeader('userType', localStorage.getItem('userType'));
                            xhr.responseType = 'blob'
                            xhr.onload = function () {
                                if (this.status == 200) {
                                    let blob = this.response
                                    let reader = new FileReader()
                                    reader.readAsDataURL(blob)
                                    reader.onload = function (e) {
                                        let a = document.createElement('a')
                                        a.download = '询价供应商' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
                                        a.href = e.target.result
                                        $('body').append(a)
                                        a.click()
                                        $(a).remove()
                                    }
                                }
                            }
                            xhr.send(form.join('&'))
                        }
                    </script>
                    <style scoped="scoped">
                        .textbox {
                            height: 20px;
                            margin: 0;
                            padding: 0 2px;
                            box-sizing: content-box;
                        }

                        /*.table tr {
height: 15px;
}*/
                    </style>
                    <div class="query_criteria" id="query_criteria">
                        <div style="margin: 5px 0px">
                            <%-- 搜索框 --%>
                                <label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
                                    name="startTime" id="startTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
                                    class="easyui-datebox" name="endTime" id="endTime"
                                    data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
                                    style="width: 150px" />
                                <%--<label style="margin-left: 20px; font-size: 12px;">状态：</label>
                                    <input class="easyui-combobox" id="status" name="status" style="width: 80px;"
                                        data-options="valueField: 'value',editable:false,
                    textField: 'label',panelHeight:'auto',data: [{
                        label: '全部',
                        value: ''
                    },{
                        label: '待提交',
                        value: '0',
                        selected:true
                    },{
                        label: '已提交',
                        value: '1'
                    }]">
                                    </input> --%>
                                    <a id="search" style="margin-left: 30px" href="javascript:void(0)"
                                        class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                        onclick="selectList()">查询</a> <a id="export" href="javascript:void(0)"
                                        class="easyui-linkbutton" data-options="iconCls:'icon-export'"
                                        onclick="exportList()">导出</a>
                                    <a id="export" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-export'" onclick="startSpeak()">开始播报</a><a
                                        id="cancel" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-export'" onclick="pauseSpeak()">暂停播放</a><a
                                        id="cancel" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-export'" onclick="resumeSpeak()">恢复播放</a><a
                                        id="cancel" href="javascript:void(0)" class="easyui-linkbutton"
                                        data-options="iconCls:'icon-export'" onclick="stopSpeak()">停止播放</a>

                        </div>

                        <table id="dg"></table>

                    </div>
        </body>
        <script>
            var list = []

            function startSpeak() {
                if (!window.SpeechSynthesisUtterance) {
                    alert('当前浏览器不支持文字转语音服务,请使用谷歌浏览器或Edge浏览器')
                    return;
                }
                list = []
                const speech = new SpeechSynthesisUtterance();
                // 查询超时未打印COA的样品信息
                const noPrintList = queryNoPrintSamples()
                // 查询已提交的样品信息
                const commitedList = queryCommitedSamples()
                // 查询未提交的样品信息
                const noCommitList = speakNoCommitSamples()
                // 合并数组
                list.push(...noPrintList, ...commitedList, ...noCommitList)

                // 有样品数据，开始播报
                if (!(Array.prototype.isPrototypeOf(list) && list.length === 0)) {
                    speak(0);
                } else {
                    $.messager.show({
                        title: 'LIMS接口回执',
                        msg: '未在LIMS系统中查询需要播报的样品信息',
                        timeout: 4000,
                        showType: 'show'
                    });
                    sleep(4000)
                    startSpeak()
                }


            }

            /**
             * 查询超时未打印COA的样品信息
             */
            function queryNoPrintSamples() {
                let param = {}
                let noPrintList = []
                $.ajax({
                    type: "post",
                    dataType: "json",
                    async: false,
                    url: 'lims/broadcasts/getLimsNoPrintCOASamples',
                    data: JSON.stringify(param),
                    contentType: "application/json",
                    success: function (data) {

                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.responseJSON.code == 60200) {
                            noPrintList = XMLHttpRequest.responseJSON.rows
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                    }
                })
                return noPrintList;
            }


            /**
             * 查询当天已提交的样品
             */
            function queryCommitedSamples() {
                let param = {}
                let commitedList = []
                $.ajax({
                    type: "post",
                    dataType: "json",
                    async: false,
                    url: 'lims/broadcasts/getLimsCommitedSamples',
                    data: JSON.stringify(param),
                    contentType: "application/json",
                    success: function (data) {

                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.responseJSON.code == 60200) {
                            commitedList = XMLHttpRequest.responseJSON.rows
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //  $.messager.alert('消息', errorThrown);
                    }
                })
                return commitedList
            }

            /**
             * 查询播报超时未提交的样品信息
             */
            function speakNoCommitSamples() {
                let param = {}
                let noCommitList = []
                $.ajax({
                    type: "post",
                    dataType: "json",
                    async: false,
                    url: 'lims/broadcasts/getLimsNoCommitSamples',
                    data: JSON.stringify(param),
                    contentType: "application/json",
                    success: function (data) {

                    },
                    complete: function (XMLHttpRequest) {
                        if (XMLHttpRequest.responseJSON.code != 60200) {
                            //  $.messager.alert('消息', XMLHttpRequest.responseJSON.msg);
                        } else {
                            noCommitList = XMLHttpRequest.responseJSON.rows
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        // $.messager.alert('消息', errorThrown);
                    }
                })
                return noCommitList
            }


            /**
             * 语音播报
             * @param noCommitObj
             * @param tag
             */
            function speak(i) {
                if (i >= list.length) {
                    sleep(4000)
                    startSpeak()
                    return
                }
                let sample = list[i]
                if (!sample) {
                    return;
                }
                let param = {}
                param.samNo = sample.samNo
                const speechUtterance = new SpeechSynthesisUtterance();
                let tag = sample.broadcastType
                if (tag == 'noCommit') {
                    // 需朗读的文字内容
                    speechUtterance.text = '样品：' + sample.samName + '已超时，请尽快提交！'
                } else if (tag == 'noPrint') {
                    // 需朗读的文字内容
                    speechUtterance.text = '样品：' + sample.samName + '未打印COA！'
                } else if (tag == 'commited') {
                    // 需朗读的文字内容
                    speechUtterance.text = '样品：' + sample.samName + '已提交！'
                }

                // 每读完一句，会触发一次
                speechUtterance.onend = function () {

                    setTimeout('speak(' + (i + 1) + ')', 600);
                    if (tag == 'noCommit') {
                        $.ajax({
                            type: "post",
                            dataType: "json",
                            async: false,
                            url: 'lims/broadcasts/updateBroadcastNumBySamNo',
                            data: JSON.stringify(param),
                            contentType: "application/json",
                            success: function (data) {

                            },
                            complete: function (XMLHttpRequest) {
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                            }
                        })
                    } else if (tag == 'noPrint') {
                        $.ajax({
                            type: "post",
                            dataType: "json",
                            async: false,
                            url: 'lims/broadcasts/updateNoPrintBroadcastNumBySamNo',
                            data: JSON.stringify(param),
                            contentType: "application/json",
                            success: function (data) {
                            },
                            complete: function (XMLHttpRequest) {
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                            }
                        })
                    } else if (tag == 'commited') {
                        $.ajax({
                            type: "post",
                            dataType: "json",
                            async: false,
                            url: 'lims/broadcasts/updateCommitedNumBySamNo',
                            data: JSON.stringify(param),
                            contentType: "application/json",
                            success: function (data) {
                            },
                            complete: function (XMLHttpRequest) {
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                            }
                        })
                    }
                }
                // 读取的语速，取值0.1~10 ，正常语速值为1
                speechUtterance.rate = 1.8
                // 读取时的语言
                speechUtterance.lang = 'zh-CN'
                // 读取时声音的音量，取值0~1，正常音量为1
                speechUtterance.volume = 2
                // 声音的音高，取值0~2 ，正常音高为1
                speechUtterance.pitch = 2
                // 开始朗读
                speechSynthesis.speak(speechUtterance);
                console.log('已读完第 ', i, ' 句')
            }

            /**
             * 取消播放
             */
            function stopSpeak() {
                window.speechSynthesis.cancel()

            }

            /**
             * 暂停播放
             */
            function pauseSpeak() {
                window.speechSynthesis.pause()

            }

            /**
             * 恢复播放
             */
            function resumeSpeak() {
                window.speechSynthesis.resume()

            }

            function sleep(ms) {
                var start = Date.now(), end = start + ms;
                while (Date.now() < end);
                return;
            }
        </script>

        </html>